package org.james.deleter.task;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.StringUtils;
import org.james.deleter.components.InfoListBox;

import javafx.application.Platform;

public class ShowMessage {

	private static final LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>();
	
	public static void addToQueue(String text){
		try {
			queue.put(text);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void queueHandler(){
		try {
			String text = queue.poll(500, TimeUnit.MILLISECONDS);
			if(StringUtils.isNotBlank(text)){
//				InfoListBox.addMessageInfo(text);
				Platform.runLater(()->InfoListBox.addMessageInfo(text));
			}
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
